package com.platform.comm.common.batch.mapper;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.RowMapper;

import javax.annotation.Nonnull;
import java.sql.ResultSet;
import java.util.Map;

/**
 * 从记录中获取内容
 *
 * @author Tommy
 */
@Slf4j
public class ComResultRowMapper implements RowMapper<Map<String, Object>> {

    private Map<String, Object> comItemMap;

    public ComResultRowMapper(Map<String, Object> comItemMap) {
        this.comItemMap = comItemMap;
    }

    @Override
    public Map<String, Object> mapRow(@Nonnull ResultSet rs, int rowNum) {
        Map<String, Object> map = Maps.newHashMap();
        comItemMap.forEach((k, v) -> {
            try {
                map.put(k, rs.getString(k));
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        });

        return map;
    }
}
